package org.example.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AnalysisEvent {
    private String type;        // 事件类型: status/sql/data/chart/summary/error
    private String step;        // 步骤名称
    private Object data;        // 事件数据
    private String message;     // 状态消息
    private Long timestamp;

    public AnalysisEvent(String type, String step, Object data, String message) {
        this.type = type;
        this.step = step;
        this.data = data;
        this.message = message;
        this.timestamp = System.currentTimeMillis();
    }

    // 静态工厂方法
    public static AnalysisEvent status(String step, String message) {
        return new AnalysisEvent("status", step, null, message);
    }

    public static AnalysisEvent sql(String sql) {
        return new AnalysisEvent("sql", "sql_generation", sql, "SQL生成完成");
    }

    public static AnalysisEvent data(List<Map<String, Object>> data) {
        return new AnalysisEvent("data", "query_execution", data, "数据查询完成");
    }

    public static AnalysisEvent chart(Object chartConfig) {
        return new AnalysisEvent("chart", "chart_generation", chartConfig, "图表配置生成完成");
    }

    public static AnalysisEvent summary(String summary) {
        return new AnalysisEvent("summary", "analysis_summary", summary, "分析总结完成");
    }

    public static AnalysisEvent error(String step, String error) {
        return new AnalysisEvent("error", step, null, error);
    }
}